<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>Cheetah Software: SharedMemoryObject&lt; T &gt; Class Template Reference</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Cheetah Software
   &#160;<span id="projectnumber">1.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="../../index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="../../namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="../../annotated.html"><span>Classes</span></a></li>
      <li><a href="../../files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="../../search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="../../search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="../../annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="../../classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="../../inherits.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="../../functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('d1/d8d/class_shared_memory_object.html','../../');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#pri-attribs">Private Attributes</a> &#124;
<a href="../../d2/de4/class_shared_memory_object-members.html">List of all members</a>  </div>
  <div class="headertitle">
<div class="title">SharedMemoryObject&lt; T &gt; Class Template Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p><code>#include &lt;<a class="el" href="../../d2/dac/_shared_memory_8h_source.html">SharedMemory.h</a>&gt;</code></p>
<div id="dynsection-0" onclick="return toggleVisibility(this)" class="dynheader closed" style="cursor:pointer;">
  <img id="dynsection-0-trigger" src="../../closed.png" alt="+"/> Inheritance diagram for SharedMemoryObject&lt; T &gt;:</div>
<div id="dynsection-0-summary" class="dynsummary" style="display:block;">
</div>
<div id="dynsection-0-content" class="dyncontent" style="display:none;">
<div class="center"><img src="../../df/dff/class_shared_memory_object__inherit__graph.png" border="0" usemap="#_shared_memory_object_3_01_t_01_4_inherit__map" alt="Inheritance graph"/></div>
<map name="_shared_memory_object_3_01_t_01_4_inherit__map" id="_shared_memory_object_3_01_t_01_4_inherit__map">
</map>
</div>
<div id="dynsection-1" onclick="return toggleVisibility(this)" class="dynheader closed" style="cursor:pointer;">
  <img id="dynsection-1-trigger" src="../../closed.png" alt="+"/> Collaboration diagram for SharedMemoryObject&lt; T &gt;:</div>
<div id="dynsection-1-summary" class="dynsummary" style="display:block;">
</div>
<div id="dynsection-1-content" class="dyncontent" style="display:none;">
<div class="center"><img src="../../df/dab/class_shared_memory_object__coll__graph.png" border="0" usemap="#_shared_memory_object_3_01_t_01_4_coll__map" alt="Collaboration graph"/></div>
<map name="_shared_memory_object_3_01_t_01_4_coll__map" id="_shared_memory_object_3_01_t_01_4_coll__map">
</map>
</div>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a379efd0ee97452b0fc87f411d2f77422"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/d8d/class_shared_memory_object.html#a379efd0ee97452b0fc87f411d2f77422">SharedMemoryObject</a> ()=default</td></tr>
<tr class="separator:a379efd0ee97452b0fc87f411d2f77422"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a6b21aa9ce01bcd55504953446dc2ab2b"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/d8d/class_shared_memory_object.html#a6b21aa9ce01bcd55504953446dc2ab2b">createNew</a> (const std::string &amp;name, bool allowOverwrite=false)</td></tr>
<tr class="separator:a6b21aa9ce01bcd55504953446dc2ab2b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a62656128cd792e54088e8f75315d05bc"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/d8d/class_shared_memory_object.html#a62656128cd792e54088e8f75315d05bc">attach</a> (const std::string &amp;name)</td></tr>
<tr class="separator:a62656128cd792e54088e8f75315d05bc"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a36d86f30045bfd852bd784a2f87fadef"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/d8d/class_shared_memory_object.html#a36d86f30045bfd852bd784a2f87fadef">closeNew</a> ()</td></tr>
<tr class="separator:a36d86f30045bfd852bd784a2f87fadef"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a1678883b8fae1cb2eb9379390f159ee1"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/d8d/class_shared_memory_object.html#a1678883b8fae1cb2eb9379390f159ee1">detach</a> ()</td></tr>
<tr class="separator:a1678883b8fae1cb2eb9379390f159ee1"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ac3647a51b19b036e3cf42ac1f2505dff"><td class="memItemLeft" align="right" valign="top">T *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/d8d/class_shared_memory_object.html#ac3647a51b19b036e3cf42ac1f2505dff">get</a> ()</td></tr>
<tr class="separator:ac3647a51b19b036e3cf42ac1f2505dff"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ace8efdc83fb4c53173ede2080ae4657a"><td class="memItemLeft" align="right" valign="top">T &amp;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/d8d/class_shared_memory_object.html#ace8efdc83fb4c53173ede2080ae4657a">operator()</a> ()</td></tr>
<tr class="separator:ace8efdc83fb4c53173ede2080ae4657a"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pri-attribs"></a>
Private Attributes</h2></td></tr>
<tr class="memitem:a0b202e4aa524a350129ba280d4bccfa7"><td class="memItemLeft" align="right" valign="top">T *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">_data</a> = nullptr</td></tr>
<tr class="separator:a0b202e4aa524a350129ba280d4bccfa7"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae7c98fa932ef353d69f12528cd727bbe"><td class="memItemLeft" align="right" valign="top">std::string&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/d8d/class_shared_memory_object.html#ae7c98fa932ef353d69f12528cd727bbe">_name</a></td></tr>
<tr class="separator:ae7c98fa932ef353d69f12528cd727bbe"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a9e22b83c4e29975d23fa681c300aa2f8"><td class="memItemLeft" align="right" valign="top">size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/d8d/class_shared_memory_object.html#a9e22b83c4e29975d23fa681c300aa2f8">_size</a></td></tr>
<tr class="separator:a9e22b83c4e29975d23fa681c300aa2f8"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0112033efeb44be6200595ff574f1f3a"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/d8d/class_shared_memory_object.html#a0112033efeb44be6200595ff574f1f3a">_fd</a></td></tr>
<tr class="separator:a0112033efeb44be6200595ff574f1f3a"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><h3>template&lt;typename T&gt;<br />
class SharedMemoryObject&lt; T &gt;</h3>

<p>A container class for an object which is stored in shared memory. This object can then be viewed in multiple processes or programs. Note that there is significant overhead when creating a shared memory object, so it is recommended that two programs that communicate should have one single large <a class="el" href="../../d1/d8d/class_shared_memory_object.html">SharedMemoryObject</a> instead of many small ones.</p>
<p>A name string is used to identify shared objects across different programs</p>
<p>Before a shared memory object can be used, you must either allocate new memory, or connect it to an existing shared memory object.</p>
<p>Creating/deleting the memory can be done with createNew/closeNew. Viewing an existing object allocated with createNew can be done with attach/detach</p>
<p>For an example, see <a class="el" href="../../d8/d5e/test__shared_memory_8cpp.html">test_sharedMemory.cpp</a> </p>

<p>Definition at line <a class="el" href="../../d2/dac/_shared_memory_8h_source.html#l00112">112</a> of file <a class="el" href="../../d2/dac/_shared_memory_8h_source.html">SharedMemory.h</a>.</p>
</div><h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a class="anchor" id="a379efd0ee97452b0fc87f411d2f77422"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="../../d1/d8d/class_shared_memory_object.html">SharedMemoryObject</a>&lt; T &gt;::<a class="el" href="../../d1/d8d/class_shared_memory_object.html">SharedMemoryObject</a> </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">default</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a class="anchor" id="a62656128cd792e54088e8f75315d05bc"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="../../d1/d8d/class_shared_memory_object.html">SharedMemoryObject</a>&lt; T &gt;::attach </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>name</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Attach to an existing shared memory object. </p>

<p>Definition at line <a class="el" href="../../d2/dac/_shared_memory_8h_source.html#l00191">191</a> of file <a class="el" href="../../d2/dac/_shared_memory_8h_source.html">SharedMemory.h</a>.</p>
<div class="fragment"><div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;                                     {</div><div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;    assert(!<a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">_data</a>);</div><div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;    <a class="code" href="../../d1/d8d/class_shared_memory_object.html#ae7c98fa932ef353d69f12528cd727bbe">_name</a> = name;</div><div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;    <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a9e22b83c4e29975d23fa681c300aa2f8">_size</a> = <span class="keyword">sizeof</span>(T);</div><div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;    printf(<span class="stringliteral">&quot;[Shared Memory] open existing %s size %ld bytes\n&quot;</span>, name.c_str(),</div><div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;           <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a9e22b83c4e29975d23fa681c300aa2f8">_size</a>);</div><div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;    <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0112033efeb44be6200595ff574f1f3a">_fd</a> = shm_open(name.c_str(), O_RDWR,</div><div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;                   S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IROTH);</div><div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;    <span class="keywordflow">if</span> (_fd == -1) {</div><div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;      printf(<span class="stringliteral">&quot;[ERROR] SharedMemoryObject::attach shm_open(%s) failed: %s\n&quot;</span>,</div><div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;             <a class="code" href="../../d1/d8d/class_shared_memory_object.html#ae7c98fa932ef353d69f12528cd727bbe">_name</a>.c_str(), strerror(errno));</div><div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;      <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;Failed to create shared memory!&quot;</span>);</div><div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;      <span class="keywordflow">return</span>;</div><div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;    }</div><div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;</div><div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;    <span class="keyword">struct </span>stat s;</div><div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160;    <span class="keywordflow">if</span> (fstat(_fd, &amp;s)) {</div><div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;      printf(<span class="stringliteral">&quot;[ERROR] SharedMemoryObject::attach(%s) stat: %s\n&quot;</span>, name.c_str(),</div><div class="line"><a name="l00209"></a><span class="lineno">  209</span>&#160;             strerror(errno));</div><div class="line"><a name="l00210"></a><span class="lineno">  210</span>&#160;      <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;Failed to create shared memory!&quot;</span>);</div><div class="line"><a name="l00211"></a><span class="lineno">  211</span>&#160;      <span class="keywordflow">return</span>;</div><div class="line"><a name="l00212"></a><span class="lineno">  212</span>&#160;    }</div><div class="line"><a name="l00213"></a><span class="lineno">  213</span>&#160;</div><div class="line"><a name="l00214"></a><span class="lineno">  214</span>&#160;    <span class="keywordflow">if</span> ((<span class="keywordtype">size_t</span>)s.st_size != <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a9e22b83c4e29975d23fa681c300aa2f8">_size</a>) {</div><div class="line"><a name="l00215"></a><span class="lineno">  215</span>&#160;      printf(</div><div class="line"><a name="l00216"></a><span class="lineno">  216</span>&#160;          <span class="stringliteral">&quot;[ERROR] SharedMemoryObject::attach(%s) on something that was &quot;</span></div><div class="line"><a name="l00217"></a><span class="lineno">  217</span>&#160;          <span class="stringliteral">&quot;incorrectly &quot;</span></div><div class="line"><a name="l00218"></a><span class="lineno">  218</span>&#160;          <span class="stringliteral">&quot;sized (size is %ld bytes, should be %ld)\n&quot;</span>,</div><div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;          <a class="code" href="../../d1/d8d/class_shared_memory_object.html#ae7c98fa932ef353d69f12528cd727bbe">_name</a>.c_str(), s.st_size, <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a9e22b83c4e29975d23fa681c300aa2f8">_size</a>);</div><div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;      <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;Failed to create shared memory!&quot;</span>);</div><div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;      <span class="keywordflow">return</span>;</div><div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;    }</div><div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;</div><div class="line"><a name="l00224"></a><span class="lineno">  224</span>&#160;    <span class="keywordtype">void</span>* mem =</div><div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160;        mmap(<span class="keyword">nullptr</span>, <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a9e22b83c4e29975d23fa681c300aa2f8">_size</a>, PROT_READ | PROT_WRITE, MAP_SHARED, _fd, 0);</div><div class="line"><a name="l00226"></a><span class="lineno">  226</span>&#160;    <span class="keywordflow">if</span> (mem == MAP_FAILED) {</div><div class="line"><a name="l00227"></a><span class="lineno">  227</span>&#160;      printf(<span class="stringliteral">&quot;[ERROR] SharedMemory::attach(%s) mmap fail: %s\n&quot;</span>, <a class="code" href="../../d1/d8d/class_shared_memory_object.html#ae7c98fa932ef353d69f12528cd727bbe">_name</a>.c_str(),</div><div class="line"><a name="l00228"></a><span class="lineno">  228</span>&#160;             strerror(errno));</div><div class="line"><a name="l00229"></a><span class="lineno">  229</span>&#160;      <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;Failed to create shared memory!&quot;</span>);</div><div class="line"><a name="l00230"></a><span class="lineno">  230</span>&#160;      <span class="keywordflow">return</span>;</div><div class="line"><a name="l00231"></a><span class="lineno">  231</span>&#160;    }</div><div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160;</div><div class="line"><a name="l00233"></a><span class="lineno">  233</span>&#160;    <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">_data</a> = (T*)mem;</div><div class="line"><a name="l00234"></a><span class="lineno">  234</span>&#160;  }</div><div class="ttc" id="class_shared_memory_object_html_a0112033efeb44be6200595ff574f1f3a"><div class="ttname"><a href="../../d1/d8d/class_shared_memory_object.html#a0112033efeb44be6200595ff574f1f3a">SharedMemoryObject::_fd</a></div><div class="ttdeci">int _fd</div><div class="ttdef"><b>Definition:</b> <a href="../../d2/dac/_shared_memory_8h_source.html#l00320">SharedMemory.h:320</a></div></div>
<div class="ttc" id="class_shared_memory_object_html_ae7c98fa932ef353d69f12528cd727bbe"><div class="ttname"><a href="../../d1/d8d/class_shared_memory_object.html#ae7c98fa932ef353d69f12528cd727bbe">SharedMemoryObject::_name</a></div><div class="ttdeci">std::string _name</div><div class="ttdef"><b>Definition:</b> <a href="../../d2/dac/_shared_memory_8h_source.html#l00318">SharedMemory.h:318</a></div></div>
<div class="ttc" id="class_shared_memory_object_html_a9e22b83c4e29975d23fa681c300aa2f8"><div class="ttname"><a href="../../d1/d8d/class_shared_memory_object.html#a9e22b83c4e29975d23fa681c300aa2f8">SharedMemoryObject::_size</a></div><div class="ttdeci">size_t _size</div><div class="ttdef"><b>Definition:</b> <a href="../../d2/dac/_shared_memory_8h_source.html#l00319">SharedMemory.h:319</a></div></div>
<div class="ttc" id="class_shared_memory_object_html_a0b202e4aa524a350129ba280d4bccfa7"><div class="ttname"><a href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">SharedMemoryObject::_data</a></div><div class="ttdeci">T * _data</div><div class="ttdef"><b>Definition:</b> <a href="../../d2/dac/_shared_memory_8h_source.html#l00317">SharedMemory.h:317</a></div></div>
</div><!-- fragment -->
<p><div id="dynsection-2" onclick="return toggleVisibility(this)" class="dynheader closed" style="cursor:pointer;">
  <img id="dynsection-2-trigger" src="../../closed.png" alt="+"/> Here is the caller graph for this function:</div>
<div id="dynsection-2-summary" class="dynsummary" style="display:block;">
</div>
<div id="dynsection-2-content" class="dyncontent" style="display:none;">
<div class="center"><img src="../../d1/d8d/class_shared_memory_object_a62656128cd792e54088e8f75315d05bc_icgraph.png" border="0" usemap="#d1/d8d/class_shared_memory_object_a62656128cd792e54088e8f75315d05bc_icgraph" alt=""/></div>
<map name="d1/d8d/class_shared_memory_object_a62656128cd792e54088e8f75315d05bc_icgraph" id="d1/d8d/class_shared_memory_object_a62656128cd792e54088e8f75315d05bc_icgraph">
</map>
</div>
</p>

</div>
</div>
<a class="anchor" id="a36d86f30045bfd852bd784a2f87fadef"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="../../d1/d8d/class_shared_memory_object.html">SharedMemoryObject</a>&lt; T &gt;::closeNew </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Free memory associated with the current open shared memory object. The object could have been opened with either attach or createNew. After calling this, no process can use this shared object </p>

<p>Definition at line <a class="el" href="../../d2/dac/_shared_memory_8h_source.html#l00241">241</a> of file <a class="el" href="../../d2/dac/_shared_memory_8h_source.html">SharedMemory.h</a>.</p>
<div class="fragment"><div class="line"><a name="l00241"></a><span class="lineno">  241</span>&#160;                  {</div><div class="line"><a name="l00242"></a><span class="lineno">  242</span>&#160;    assert(<a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">_data</a>);</div><div class="line"><a name="l00243"></a><span class="lineno">  243</span>&#160;    <span class="comment">// first, unmap</span></div><div class="line"><a name="l00244"></a><span class="lineno">  244</span>&#160;    <span class="keywordflow">if</span> (munmap((<span class="keywordtype">void</span>*)<a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">_data</a>, <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a9e22b83c4e29975d23fa681c300aa2f8">_size</a>)) {</div><div class="line"><a name="l00245"></a><span class="lineno">  245</span>&#160;      printf(<span class="stringliteral">&quot;[ERROR] SharedMemoryObject::closeNew (%s) munmap %s\n&quot;</span>,</div><div class="line"><a name="l00246"></a><span class="lineno">  246</span>&#160;             <a class="code" href="../../d1/d8d/class_shared_memory_object.html#ae7c98fa932ef353d69f12528cd727bbe">_name</a>.c_str(), strerror(errno));</div><div class="line"><a name="l00247"></a><span class="lineno">  247</span>&#160;      <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;Failed to create shared memory!&quot;</span>);</div><div class="line"><a name="l00248"></a><span class="lineno">  248</span>&#160;      <span class="keywordflow">return</span>;</div><div class="line"><a name="l00249"></a><span class="lineno">  249</span>&#160;    }</div><div class="line"><a name="l00250"></a><span class="lineno">  250</span>&#160;</div><div class="line"><a name="l00251"></a><span class="lineno">  251</span>&#160;    <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">_data</a> = <span class="keyword">nullptr</span>;</div><div class="line"><a name="l00252"></a><span class="lineno">  252</span>&#160;</div><div class="line"><a name="l00253"></a><span class="lineno">  253</span>&#160;    <span class="keywordflow">if</span> (shm_unlink(<a class="code" href="../../d1/d8d/class_shared_memory_object.html#ae7c98fa932ef353d69f12528cd727bbe">_name</a>.c_str())) {</div><div class="line"><a name="l00254"></a><span class="lineno">  254</span>&#160;      printf(<span class="stringliteral">&quot;[ERROR] SharedMemoryObject::closeNew (%s) shm_unlink %s\n&quot;</span>,</div><div class="line"><a name="l00255"></a><span class="lineno">  255</span>&#160;             <a class="code" href="../../d1/d8d/class_shared_memory_object.html#ae7c98fa932ef353d69f12528cd727bbe">_name</a>.c_str(), strerror(errno));</div><div class="line"><a name="l00256"></a><span class="lineno">  256</span>&#160;      <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;Failed to create shared memory!&quot;</span>);</div><div class="line"><a name="l00257"></a><span class="lineno">  257</span>&#160;      <span class="keywordflow">return</span>;</div><div class="line"><a name="l00258"></a><span class="lineno">  258</span>&#160;    }</div><div class="line"><a name="l00259"></a><span class="lineno">  259</span>&#160;</div><div class="line"><a name="l00260"></a><span class="lineno">  260</span>&#160;    <span class="comment">// close fd</span></div><div class="line"><a name="l00261"></a><span class="lineno">  261</span>&#160;    <span class="keywordflow">if</span> (close(<a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0112033efeb44be6200595ff574f1f3a">_fd</a>)) {</div><div class="line"><a name="l00262"></a><span class="lineno">  262</span>&#160;      printf(<span class="stringliteral">&quot;[ERROR] SharedMemoryObject::closeNew (%s) close %s\n&quot;</span>,</div><div class="line"><a name="l00263"></a><span class="lineno">  263</span>&#160;             <a class="code" href="../../d1/d8d/class_shared_memory_object.html#ae7c98fa932ef353d69f12528cd727bbe">_name</a>.c_str(), strerror(errno));</div><div class="line"><a name="l00264"></a><span class="lineno">  264</span>&#160;      <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;Failed to create shared memory!&quot;</span>);</div><div class="line"><a name="l00265"></a><span class="lineno">  265</span>&#160;      <span class="keywordflow">return</span>;</div><div class="line"><a name="l00266"></a><span class="lineno">  266</span>&#160;    }</div><div class="line"><a name="l00267"></a><span class="lineno">  267</span>&#160;</div><div class="line"><a name="l00268"></a><span class="lineno">  268</span>&#160;    <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0112033efeb44be6200595ff574f1f3a">_fd</a> = 0;</div><div class="line"><a name="l00269"></a><span class="lineno">  269</span>&#160;  }</div><div class="ttc" id="class_shared_memory_object_html_a0112033efeb44be6200595ff574f1f3a"><div class="ttname"><a href="../../d1/d8d/class_shared_memory_object.html#a0112033efeb44be6200595ff574f1f3a">SharedMemoryObject::_fd</a></div><div class="ttdeci">int _fd</div><div class="ttdef"><b>Definition:</b> <a href="../../d2/dac/_shared_memory_8h_source.html#l00320">SharedMemory.h:320</a></div></div>
<div class="ttc" id="class_shared_memory_object_html_ae7c98fa932ef353d69f12528cd727bbe"><div class="ttname"><a href="../../d1/d8d/class_shared_memory_object.html#ae7c98fa932ef353d69f12528cd727bbe">SharedMemoryObject::_name</a></div><div class="ttdeci">std::string _name</div><div class="ttdef"><b>Definition:</b> <a href="../../d2/dac/_shared_memory_8h_source.html#l00318">SharedMemory.h:318</a></div></div>
<div class="ttc" id="class_shared_memory_object_html_a9e22b83c4e29975d23fa681c300aa2f8"><div class="ttname"><a href="../../d1/d8d/class_shared_memory_object.html#a9e22b83c4e29975d23fa681c300aa2f8">SharedMemoryObject::_size</a></div><div class="ttdeci">size_t _size</div><div class="ttdef"><b>Definition:</b> <a href="../../d2/dac/_shared_memory_8h_source.html#l00319">SharedMemory.h:319</a></div></div>
<div class="ttc" id="class_shared_memory_object_html_a0b202e4aa524a350129ba280d4bccfa7"><div class="ttname"><a href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">SharedMemoryObject::_data</a></div><div class="ttdeci">T * _data</div><div class="ttdef"><b>Definition:</b> <a href="../../d2/dac/_shared_memory_8h_source.html#l00317">SharedMemory.h:317</a></div></div>
</div><!-- fragment -->
<p><div id="dynsection-3" onclick="return toggleVisibility(this)" class="dynheader closed" style="cursor:pointer;">
  <img id="dynsection-3-trigger" src="../../closed.png" alt="+"/> Here is the caller graph for this function:</div>
<div id="dynsection-3-summary" class="dynsummary" style="display:block;">
</div>
<div id="dynsection-3-content" class="dyncontent" style="display:none;">
<div class="center"><img src="../../d1/d8d/class_shared_memory_object_a36d86f30045bfd852bd784a2f87fadef_icgraph.png" border="0" usemap="#d1/d8d/class_shared_memory_object_a36d86f30045bfd852bd784a2f87fadef_icgraph" alt=""/></div>
<map name="d1/d8d/class_shared_memory_object_a36d86f30045bfd852bd784a2f87fadef_icgraph" id="d1/d8d/class_shared_memory_object_a36d86f30045bfd852bd784a2f87fadef_icgraph">
</map>
</div>
</p>

</div>
</div>
<a class="anchor" id="a6b21aa9ce01bcd55504953446dc2ab2b"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">bool <a class="el" href="../../d1/d8d/class_shared_memory_object.html">SharedMemoryObject</a>&lt; T &gt;::createNew </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>name</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>allowOverwrite</em> = <code>false</code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Allocate memory for the shared memory object and attach to it. If allowOverwrite is true, and there's already an object with this name, the old object is overwritten Note that if this happens, the object may be initialized in a very weird state.</p>
<p>Otherwise, if an object with the name already exists, throws a std::runtime_error </p>

<p>Definition at line <a class="el" href="../../d2/dac/_shared_memory_8h_source.html#l00125">125</a> of file <a class="el" href="../../d2/dac/_shared_memory_8h_source.html">SharedMemory.h</a>.</p>
<div class="fragment"><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;                                                                     {</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;    <span class="keywordtype">bool</span> hadToDelete = <span class="keyword">false</span>;</div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;    assert(!<a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">_data</a>);</div><div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;    <a class="code" href="../../d1/d8d/class_shared_memory_object.html#ae7c98fa932ef353d69f12528cd727bbe">_name</a> = name;</div><div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;    <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a9e22b83c4e29975d23fa681c300aa2f8">_size</a> = <span class="keyword">sizeof</span>(T);</div><div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;    printf(<span class="stringliteral">&quot;[Shared Memory] open new %s, size %ld bytes\n&quot;</span>, name.c_str(),</div><div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;           <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a9e22b83c4e29975d23fa681c300aa2f8">_size</a>);</div><div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;</div><div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;    <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0112033efeb44be6200595ff574f1f3a">_fd</a> = shm_open(name.c_str(), O_RDWR | O_CREAT,</div><div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;                   S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IROTH);</div><div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;    <span class="keywordflow">if</span> (_fd == -1) {</div><div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;      printf(<span class="stringliteral">&quot;[ERROR] SharedMemoryObject shm_open failed: %s\n&quot;</span>,</div><div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;             strerror(errno));</div><div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;      <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;Failed to create shared memory!&quot;</span>);</div><div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;      <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;    }</div><div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;</div><div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;    <span class="keyword">struct </span>stat s;</div><div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;    <span class="keywordflow">if</span> (fstat(_fd, &amp;s)) {</div><div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;      printf(<span class="stringliteral">&quot;[ERROR] SharedMemoryObject::createNew(%s) stat: %s\n&quot;</span>,</div><div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;             name.c_str(), strerror(errno));</div><div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;      <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;Failed to create shared memory!&quot;</span>);</div><div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;      <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;    }</div><div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;</div><div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;    <span class="keywordflow">if</span> (s.st_size) {</div><div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;      printf(</div><div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;          <span class="stringliteral">&quot;[Shared Memory] SharedMemoryObject::createNew(%s) on something that &quot;</span></div><div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;          <span class="stringliteral">&quot;wasn&#39;t new (size is %ld bytes)\n&quot;</span>,</div><div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;          <a class="code" href="../../d1/d8d/class_shared_memory_object.html#ae7c98fa932ef353d69f12528cd727bbe">_name</a>.c_str(), s.st_size);</div><div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;      hadToDelete = <span class="keyword">true</span>;</div><div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;      <span class="keywordflow">if</span> (!allowOverwrite)</div><div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;        <span class="keywordflow">throw</span> std::runtime_error(</div><div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;            <span class="stringliteral">&quot;Failed to create shared memory - it already exists.&quot;</span>);</div><div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;      printf(<span class="stringliteral">&quot;\tusing existing shared memory!\n&quot;</span>);</div><div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;      <span class="comment">// return false;</span></div><div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;    }</div><div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;</div><div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;    <span class="keywordflow">if</span> (ftruncate(_fd, <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a9e22b83c4e29975d23fa681c300aa2f8">_size</a>)) {</div><div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;      printf(<span class="stringliteral">&quot;[ERROR] SharedMemoryObject::createNew(%s) ftruncate(%ld): %s\n&quot;</span>,</div><div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;             name.c_str(), <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a9e22b83c4e29975d23fa681c300aa2f8">_size</a>, strerror(errno));</div><div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;      <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;Failed to create shared memory!&quot;</span>);</div><div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;      <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;    }</div><div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;</div><div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;    <span class="keywordtype">void</span>* mem =</div><div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;        mmap(<span class="keyword">nullptr</span>, <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a9e22b83c4e29975d23fa681c300aa2f8">_size</a>, PROT_READ | PROT_WRITE, MAP_SHARED, _fd, 0);</div><div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;    <span class="keywordflow">if</span> (mem == MAP_FAILED) {</div><div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;      printf(<span class="stringliteral">&quot;[ERROR] SharedMemory::createNew(%s) mmap fail: %s\n&quot;</span>,</div><div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;             <a class="code" href="../../d1/d8d/class_shared_memory_object.html#ae7c98fa932ef353d69f12528cd727bbe">_name</a>.c_str(), strerror(errno));</div><div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;      <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;Failed to create shared memory!&quot;</span>);</div><div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;      <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;    }</div><div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;</div><div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;    <span class="comment">// there is a chance that the shared memory is not zeroed if we are reusing</span></div><div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;    <span class="comment">// old memory. this causes all sorts of weird issues, especially if the</span></div><div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;    <span class="comment">// layout of the object in memory has changed.</span></div><div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;    memset(mem, 0, <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a9e22b83c4e29975d23fa681c300aa2f8">_size</a>);</div><div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;</div><div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;    <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">_data</a> = (T*)mem;</div><div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;    <span class="keywordflow">return</span> hadToDelete;</div><div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;  }</div><div class="ttc" id="class_shared_memory_object_html_a0112033efeb44be6200595ff574f1f3a"><div class="ttname"><a href="../../d1/d8d/class_shared_memory_object.html#a0112033efeb44be6200595ff574f1f3a">SharedMemoryObject::_fd</a></div><div class="ttdeci">int _fd</div><div class="ttdef"><b>Definition:</b> <a href="../../d2/dac/_shared_memory_8h_source.html#l00320">SharedMemory.h:320</a></div></div>
<div class="ttc" id="class_shared_memory_object_html_ae7c98fa932ef353d69f12528cd727bbe"><div class="ttname"><a href="../../d1/d8d/class_shared_memory_object.html#ae7c98fa932ef353d69f12528cd727bbe">SharedMemoryObject::_name</a></div><div class="ttdeci">std::string _name</div><div class="ttdef"><b>Definition:</b> <a href="../../d2/dac/_shared_memory_8h_source.html#l00318">SharedMemory.h:318</a></div></div>
<div class="ttc" id="class_shared_memory_object_html_a9e22b83c4e29975d23fa681c300aa2f8"><div class="ttname"><a href="../../d1/d8d/class_shared_memory_object.html#a9e22b83c4e29975d23fa681c300aa2f8">SharedMemoryObject::_size</a></div><div class="ttdeci">size_t _size</div><div class="ttdef"><b>Definition:</b> <a href="../../d2/dac/_shared_memory_8h_source.html#l00319">SharedMemory.h:319</a></div></div>
<div class="ttc" id="class_shared_memory_object_html_a0b202e4aa524a350129ba280d4bccfa7"><div class="ttname"><a href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">SharedMemoryObject::_data</a></div><div class="ttdeci">T * _data</div><div class="ttdef"><b>Definition:</b> <a href="../../d2/dac/_shared_memory_8h_source.html#l00317">SharedMemory.h:317</a></div></div>
</div><!-- fragment -->
<p><div id="dynsection-4" onclick="return toggleVisibility(this)" class="dynheader closed" style="cursor:pointer;">
  <img id="dynsection-4-trigger" src="../../closed.png" alt="+"/> Here is the caller graph for this function:</div>
<div id="dynsection-4-summary" class="dynsummary" style="display:block;">
</div>
<div id="dynsection-4-content" class="dyncontent" style="display:none;">
<div class="center"><img src="../../d1/d8d/class_shared_memory_object_a6b21aa9ce01bcd55504953446dc2ab2b_icgraph.png" border="0" usemap="#d1/d8d/class_shared_memory_object_a6b21aa9ce01bcd55504953446dc2ab2b_icgraph" alt=""/></div>
<map name="d1/d8d/class_shared_memory_object_a6b21aa9ce01bcd55504953446dc2ab2b_icgraph" id="d1/d8d/class_shared_memory_object_a6b21aa9ce01bcd55504953446dc2ab2b_icgraph">
</map>
</div>
</p>

</div>
</div>
<a class="anchor" id="a1678883b8fae1cb2eb9379390f159ee1"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="../../d1/d8d/class_shared_memory_object.html">SharedMemoryObject</a>&lt; T &gt;::detach </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Close this view of the currently opened shared memory object. The object can be opened with either attach or createNew. After calling this, this process can no longer use this shared object, but other processes still can. </p>

<p>Definition at line <a class="el" href="../../d2/dac/_shared_memory_8h_source.html#l00277">277</a> of file <a class="el" href="../../d2/dac/_shared_memory_8h_source.html">SharedMemory.h</a>.</p>
<div class="fragment"><div class="line"><a name="l00277"></a><span class="lineno">  277</span>&#160;                {</div><div class="line"><a name="l00278"></a><span class="lineno">  278</span>&#160;    assert(<a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">_data</a>);</div><div class="line"><a name="l00279"></a><span class="lineno">  279</span>&#160;    <span class="comment">// first, unmap</span></div><div class="line"><a name="l00280"></a><span class="lineno">  280</span>&#160;    <span class="keywordflow">if</span> (munmap((<span class="keywordtype">void</span>*)<a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">_data</a>, <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a9e22b83c4e29975d23fa681c300aa2f8">_size</a>)) {</div><div class="line"><a name="l00281"></a><span class="lineno">  281</span>&#160;      printf(<span class="stringliteral">&quot;[ERROR] SharedMemoryObject::detach (%s) munmap %s\n&quot;</span>,</div><div class="line"><a name="l00282"></a><span class="lineno">  282</span>&#160;             <a class="code" href="../../d1/d8d/class_shared_memory_object.html#ae7c98fa932ef353d69f12528cd727bbe">_name</a>.c_str(), strerror(errno));</div><div class="line"><a name="l00283"></a><span class="lineno">  283</span>&#160;      <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;Failed to create shared memory!&quot;</span>);</div><div class="line"><a name="l00284"></a><span class="lineno">  284</span>&#160;      <span class="keywordflow">return</span>;</div><div class="line"><a name="l00285"></a><span class="lineno">  285</span>&#160;    }</div><div class="line"><a name="l00286"></a><span class="lineno">  286</span>&#160;</div><div class="line"><a name="l00287"></a><span class="lineno">  287</span>&#160;    <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">_data</a> = <span class="keyword">nullptr</span>;</div><div class="line"><a name="l00288"></a><span class="lineno">  288</span>&#160;</div><div class="line"><a name="l00289"></a><span class="lineno">  289</span>&#160;    <span class="comment">// close fd</span></div><div class="line"><a name="l00290"></a><span class="lineno">  290</span>&#160;    <span class="keywordflow">if</span> (close(<a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0112033efeb44be6200595ff574f1f3a">_fd</a>)) {</div><div class="line"><a name="l00291"></a><span class="lineno">  291</span>&#160;      printf(<span class="stringliteral">&quot;[ERROR] SharedMemoryObject::detach (%s) close %s\n&quot;</span>,</div><div class="line"><a name="l00292"></a><span class="lineno">  292</span>&#160;             <a class="code" href="../../d1/d8d/class_shared_memory_object.html#ae7c98fa932ef353d69f12528cd727bbe">_name</a>.c_str(), strerror(errno));</div><div class="line"><a name="l00293"></a><span class="lineno">  293</span>&#160;      <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">&quot;Failed to create shared memory!&quot;</span>);</div><div class="line"><a name="l00294"></a><span class="lineno">  294</span>&#160;      <span class="keywordflow">return</span>;</div><div class="line"><a name="l00295"></a><span class="lineno">  295</span>&#160;    }</div><div class="line"><a name="l00296"></a><span class="lineno">  296</span>&#160;</div><div class="line"><a name="l00297"></a><span class="lineno">  297</span>&#160;    <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0112033efeb44be6200595ff574f1f3a">_fd</a> = 0;</div><div class="line"><a name="l00298"></a><span class="lineno">  298</span>&#160;  }</div><div class="ttc" id="class_shared_memory_object_html_a0112033efeb44be6200595ff574f1f3a"><div class="ttname"><a href="../../d1/d8d/class_shared_memory_object.html#a0112033efeb44be6200595ff574f1f3a">SharedMemoryObject::_fd</a></div><div class="ttdeci">int _fd</div><div class="ttdef"><b>Definition:</b> <a href="../../d2/dac/_shared_memory_8h_source.html#l00320">SharedMemory.h:320</a></div></div>
<div class="ttc" id="class_shared_memory_object_html_ae7c98fa932ef353d69f12528cd727bbe"><div class="ttname"><a href="../../d1/d8d/class_shared_memory_object.html#ae7c98fa932ef353d69f12528cd727bbe">SharedMemoryObject::_name</a></div><div class="ttdeci">std::string _name</div><div class="ttdef"><b>Definition:</b> <a href="../../d2/dac/_shared_memory_8h_source.html#l00318">SharedMemory.h:318</a></div></div>
<div class="ttc" id="class_shared_memory_object_html_a9e22b83c4e29975d23fa681c300aa2f8"><div class="ttname"><a href="../../d1/d8d/class_shared_memory_object.html#a9e22b83c4e29975d23fa681c300aa2f8">SharedMemoryObject::_size</a></div><div class="ttdeci">size_t _size</div><div class="ttdef"><b>Definition:</b> <a href="../../d2/dac/_shared_memory_8h_source.html#l00319">SharedMemory.h:319</a></div></div>
<div class="ttc" id="class_shared_memory_object_html_a0b202e4aa524a350129ba280d4bccfa7"><div class="ttname"><a href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">SharedMemoryObject::_data</a></div><div class="ttdeci">T * _data</div><div class="ttdef"><b>Definition:</b> <a href="../../d2/dac/_shared_memory_8h_source.html#l00317">SharedMemory.h:317</a></div></div>
</div><!-- fragment -->
<p><div id="dynsection-5" onclick="return toggleVisibility(this)" class="dynheader closed" style="cursor:pointer;">
  <img id="dynsection-5-trigger" src="../../closed.png" alt="+"/> Here is the caller graph for this function:</div>
<div id="dynsection-5-summary" class="dynsummary" style="display:block;">
</div>
<div id="dynsection-5-content" class="dyncontent" style="display:none;">
<div class="center"><img src="../../d1/d8d/class_shared_memory_object_a1678883b8fae1cb2eb9379390f159ee1_icgraph.png" border="0" usemap="#d1/d8d/class_shared_memory_object_a1678883b8fae1cb2eb9379390f159ee1_icgraph" alt=""/></div>
<map name="d1/d8d/class_shared_memory_object_a1678883b8fae1cb2eb9379390f159ee1_icgraph" id="d1/d8d/class_shared_memory_object_a1678883b8fae1cb2eb9379390f159ee1_icgraph">
</map>
</div>
</p>

</div>
</div>
<a class="anchor" id="ac3647a51b19b036e3cf42ac1f2505dff"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">T* <a class="el" href="../../d1/d8d/class_shared_memory_object.html">SharedMemoryObject</a>&lt; T &gt;::get </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Get the shared memory object. </p>

<p>Definition at line <a class="el" href="../../d2/dac/_shared_memory_8h_source.html#l00303">303</a> of file <a class="el" href="../../d2/dac/_shared_memory_8h_source.html">SharedMemory.h</a>.</p>
<div class="fragment"><div class="line"><a name="l00303"></a><span class="lineno">  303</span>&#160;           {</div><div class="line"><a name="l00304"></a><span class="lineno">  304</span>&#160;    assert(<a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">_data</a>);</div><div class="line"><a name="l00305"></a><span class="lineno">  305</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">_data</a>;</div><div class="line"><a name="l00306"></a><span class="lineno">  306</span>&#160;  }</div><div class="ttc" id="class_shared_memory_object_html_a0b202e4aa524a350129ba280d4bccfa7"><div class="ttname"><a href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">SharedMemoryObject::_data</a></div><div class="ttdeci">T * _data</div><div class="ttdef"><b>Definition:</b> <a href="../../d2/dac/_shared_memory_8h_source.html#l00317">SharedMemory.h:317</a></div></div>
</div><!-- fragment -->
<p><div id="dynsection-6" onclick="return toggleVisibility(this)" class="dynheader closed" style="cursor:pointer;">
  <img id="dynsection-6-trigger" src="../../closed.png" alt="+"/> Here is the caller graph for this function:</div>
<div id="dynsection-6-summary" class="dynsummary" style="display:block;">
</div>
<div id="dynsection-6-content" class="dyncontent" style="display:none;">
<div class="center"><img src="../../d1/d8d/class_shared_memory_object_ac3647a51b19b036e3cf42ac1f2505dff_icgraph.png" border="0" usemap="#d1/d8d/class_shared_memory_object_ac3647a51b19b036e3cf42ac1f2505dff_icgraph" alt=""/></div>
<map name="d1/d8d/class_shared_memory_object_ac3647a51b19b036e3cf42ac1f2505dff_icgraph" id="d1/d8d/class_shared_memory_object_ac3647a51b19b036e3cf42ac1f2505dff_icgraph">
</map>
</div>
</p>

</div>
</div>
<a class="anchor" id="ace8efdc83fb4c53173ede2080ae4657a"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">T&amp; <a class="el" href="../../d1/d8d/class_shared_memory_object.html">SharedMemoryObject</a>&lt; T &gt;::operator() </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Get the shared memory object. </p>

<p>Definition at line <a class="el" href="../../d2/dac/_shared_memory_8h_source.html#l00311">311</a> of file <a class="el" href="../../d2/dac/_shared_memory_8h_source.html">SharedMemory.h</a>.</p>
<div class="fragment"><div class="line"><a name="l00311"></a><span class="lineno">  311</span>&#160;                  {</div><div class="line"><a name="l00312"></a><span class="lineno">  312</span>&#160;    assert(<a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">_data</a>);</div><div class="line"><a name="l00313"></a><span class="lineno">  313</span>&#160;    <span class="keywordflow">return</span> *<a class="code" href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">_data</a>;</div><div class="line"><a name="l00314"></a><span class="lineno">  314</span>&#160;  }</div><div class="ttc" id="class_shared_memory_object_html_a0b202e4aa524a350129ba280d4bccfa7"><div class="ttname"><a href="../../d1/d8d/class_shared_memory_object.html#a0b202e4aa524a350129ba280d4bccfa7">SharedMemoryObject::_data</a></div><div class="ttdeci">T * _data</div><div class="ttdef"><b>Definition:</b> <a href="../../d2/dac/_shared_memory_8h_source.html#l00317">SharedMemory.h:317</a></div></div>
</div><!-- fragment -->
</div>
</div>
<h2 class="groupheader">Member Data Documentation</h2>
<a class="anchor" id="a0b202e4aa524a350129ba280d4bccfa7"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">T* <a class="el" href="../../d1/d8d/class_shared_memory_object.html">SharedMemoryObject</a>&lt; T &gt;::_data = nullptr</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Definition at line <a class="el" href="../../d2/dac/_shared_memory_8h_source.html#l00317">317</a> of file <a class="el" href="../../d2/dac/_shared_memory_8h_source.html">SharedMemory.h</a>.</p>

</div>
</div>
<a class="anchor" id="a0112033efeb44be6200595ff574f1f3a"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">int <a class="el" href="../../d1/d8d/class_shared_memory_object.html">SharedMemoryObject</a>&lt; T &gt;::_fd</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Definition at line <a class="el" href="../../d2/dac/_shared_memory_8h_source.html#l00320">320</a> of file <a class="el" href="../../d2/dac/_shared_memory_8h_source.html">SharedMemory.h</a>.</p>

</div>
</div>
<a class="anchor" id="ae7c98fa932ef353d69f12528cd727bbe"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">std::string <a class="el" href="../../d1/d8d/class_shared_memory_object.html">SharedMemoryObject</a>&lt; T &gt;::_name</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Definition at line <a class="el" href="../../d2/dac/_shared_memory_8h_source.html#l00318">318</a> of file <a class="el" href="../../d2/dac/_shared_memory_8h_source.html">SharedMemory.h</a>.</p>

</div>
</div>
<a class="anchor" id="a9e22b83c4e29975d23fa681c300aa2f8"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">size_t <a class="el" href="../../d1/d8d/class_shared_memory_object.html">SharedMemoryObject</a>&lt; T &gt;::_size</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">private</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Definition at line <a class="el" href="../../d2/dac/_shared_memory_8h_source.html#l00319">319</a> of file <a class="el" href="../../d2/dac/_shared_memory_8h_source.html">SharedMemory.h</a>.</p>

</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="../../d2/dac/_shared_memory_8h_source.html">SharedMemory.h</a></li>
</ul>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="../../d1/d8d/class_shared_memory_object.html">SharedMemoryObject</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="../../doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
